package com.ruoyi.psi.sale.collection.domain;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModelProperty;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.List;

/**
 * 销售收款
 * psi_sale_collection
 * @author Drj 2021/6/28
 * 修改：lsy 2021.7.17
 */
public class SaleCollection extends BaseEntity {
    /**
     * 销售收款编号
     */
    @NotNull(message = "销售收款编号不能为空")
    @ApiModelProperty(value = "销售收款编号", required = true)
    private String collectionId;
    /**
     * 客户编号
     */
    @NotNull(message = "客户编号不能为空")
    @ApiModelProperty(value = "客户编号", required = true)
    private String customerInfoId;
    /**
     * 客户名称
     */
    @ApiModelProperty("客户名称")
    private String customerInfoName;
    /**
     * 收款时间
     */
    @ApiModelProperty(value = "收款时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private java.sql.Timestamp collectionTime;

    /**
     * 本次收款总金额
     */
    @ApiModelProperty("本次收款总金额")
    private Double collectionAmountTotal;
    /**
     * 本次收款总优惠金额
     * 数据库查询
     */
    @ApiModelProperty("本次收款总优惠金额")
    private Double discountAmount;
    /**
     * 本次收款总实收金额
     */
    @ApiModelProperty("本次收款总实收金额")
    private Double  actualAmountTotal;
    /**
     * 本次收款总应收金额
     * 销售订单金额总和
     */
    @ApiModelProperty("销售订单金额总和")
    private Double receivableAmountTotal;
    /**
     * 创建时间
     */
    @ApiModelProperty("创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private java.sql.Timestamp createTime;
    /**
     * 备注
     */
    @ApiModelProperty("备注")
    private String remark;
    /**
     * 收款明细
     */
    private List<CollectionList> collectionLists;

    public List<CollectionList> getCollectionLists() {
        return collectionLists;
    }

    public void setCollectionLists(List<CollectionList> collectionLists) {
        BigDecimal bigDecimalCAT = new BigDecimal("0");//collectionAmountTotal,本次收款总金额
        BigDecimal bigDecimalAAT = new BigDecimal("0");//actualAmountTotal,本次收款总实收金额
        BigDecimal bigDecimalRAT = new BigDecimal("0");//receivableAmountTotal,本次收款总应收金额
        for (int i = 0; i < collectionLists.size(); i++) {
            bigDecimalCAT = bigDecimalCAT.add(BigDecimal.valueOf(collectionLists.get(i).getCollectionAmount()));//收款金额累加
            bigDecimalRAT = bigDecimalRAT.add(BigDecimal.valueOf(collectionLists.get(i).getSalePriceTotal()));//订单金额累加
        }
        bigDecimalAAT = bigDecimalCAT.subtract(BigDecimal.valueOf(this.discountAmount)); //本次收款总实收金额 = 本次收款总金额 - 本次收款总优惠金额
        //存入类中
        setCollectionAmountTotal(bigDecimalCAT.doubleValue());
        setActualAmountTotal(bigDecimalAAT.doubleValue());
        setReceivableAmountTotal(bigDecimalRAT.doubleValue());
        this.collectionLists = collectionLists;
    }

    public String getCollectionId() {
        return collectionId;
    }

    public void setCollectionId(String collectionId) {
        this.collectionId = collectionId;
    }



    public String getCustomerInfoId() {
        return customerInfoId;
    }

    public void setCustomerInfoId(String customerInfoId) {
        this.customerInfoId = customerInfoId;
    }

    public String getCustomerInfoName() {
        return customerInfoName;
    }

    public void setCustomerInfoName(String customerInfoName) {
        this.customerInfoName = customerInfoName;
    }

    public Timestamp getCollectionTime() {
        return collectionTime;
    }

    public void setCollectionTime(Timestamp collectionTime) {
        this.collectionTime = collectionTime;
    }

    public Double getCollectionAmountTotal() {
        return collectionAmountTotal;
    }

    public void setCollectionAmountTotal(Double collectionAmountTotal) {
        this.collectionAmountTotal = collectionAmountTotal;
    }

    public Double getDiscountAmount() {
        return discountAmount;
    }

    public void setDiscountAmount(Double discountAmount) {
        this.discountAmount = discountAmount;
    }

    public Double getActualAmountTotal() {
        return actualAmountTotal;
    }

    public void setActualAmountTotal(Double actualAmountTotal) {
        this.actualAmountTotal = actualAmountTotal;
    }

    public Double getReceivableAmountTotal() {
        return receivableAmountTotal;
    }

    public void setReceivableAmountTotal(Double receivableAmountTotal) {
        this.receivableAmountTotal = receivableAmountTotal;
    }

    @Override
    public Timestamp getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Timestamp createTime) {
        this.createTime = createTime;
    }

    @Override
    public String getRemark() {
        return remark;
    }

    @Override
    public void setRemark(String remark) {
        this.remark = remark;
    }
}
